﻿using BBCore.Core.Models.Admins;
using BootstrapBlazor.Components;
using System.Reflection.Metadata;
using BBCore.Infrastructure.Helps;
using Custom_EditMenu= BBCore.Server.Components.Pages.Admins;

namespace BBCore.Server.Components.Pages.Admins
{
    public partial class Role
    {
        private async Task EditMenu(int roleId)
        {
            List<MenuEntity> menuEntities = [];
            var result = await DialogService.ShowModal<EditMenu>(new ResultDialogOption()
            {
                Title ="菜单分配",
                ComponentParameters = new Dictionary<string, object>()
                {
                    [nameof(Custom_EditMenu.EditMenu.RoleId)] = roleId,
                    [nameof(Custom_EditMenu.EditMenu.MenuCallback)] = new Action<List<MenuEntity>>(list => menuEntities = list)
                }
            });
            if (result == DialogResult.Yes)
            {
                await ToastService.Show(new ToastOption()
                {
                    Category = ToastCategory.Success,
                    Title = "保存成功",
                    Content = "菜单分配成功,4秒后自动关闭"
                });

                //消息分发,通知用户菜单有更新.
                //DispatchService.Dispatch(new DispatchEntry<string>()
                //{
                //    Name = BBCore_Constant.RefreshMenuKey,
                //    Entry = roleId.ToString()
                //});
            }
            //System.Console.WriteLine(menuEntities.Count);
        }

    }
}
